{% raw %} aes

Construct aesthetic mappings and then convert them with ggplotly

p <-  ggplot(mpg, aes(displ, hwy)) + geom_point()
plotly::ggplotly(p)
p <-  ggplot(mpg) + geom_point(aes(displ, hwy))
plotly::ggplotly(p)
scatter_by <- function(data, ...) {
  ggplot(data) + geom_point(aes(...))
}
p <-  scatter_by(mtcars, disp, drat)
plotly::ggplotly(p)
scatter_by <- function(data, x, y) {
  x <- enquo(x)
  y <- enquo(y)

  ggplot(data) + geom_point(aes(!!x, !!y))
}
p <-  scatter_by(mtcars, disp, drat)
plotly::ggplotly(p)
cut3 <- function(x) cut_number(x, 3)
p <-  scatter_by(mtcars, cut3(disp), drat)
plotly::ggplotly(p)
{% endraw %}